/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Registrasi extends HttpServlet{
    
    @Override
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
    @Override
public void doPost(HttpServletRequest req, HttpServletResponse res) 
throws ServletException, IOException{
String connectionURL = "jdbc:mysql://localhost:3306/travel_online";
Connection connection=null;
ResultSet rs;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String nama_trevel = req.getParameter("nama_trevel");
String alamat = req.getParameter("alamat");
String kota = req.getParameter("kota");
String kode_pos = req.getParameter("kode_pos");
String telepon = req.getParameter("telepon");
String email = req.getParameter("email");
String password = req.getParameter("password");
String confirm_password = req.getParameter("confirm_password");


try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", null); 
String sql = "insert into account values (?,?,?,?,?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, id);
pst.setString(2, nama_trevel);
pst.setString(3, alamat);
pst.setString(4, kota);
pst.setString(5, kode_pos);
pst.setString(6, telepon);
pst.setString(7, email);
pst.setString(8, password);
pst.setString(9, confirm_password);


int numRowsChanged = pst.executeUpdate();
out.println("<h2>Silahkan Login terlebih dahulu...</h2>");
out.println("<body><h1>" +  "</h1>");
out.println("<a href=\"login.jsp\">login</a><br>");
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
out.println(e);
}
finally {

try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
}
}